package cn.edu.sdjzu.xg.eagle.controller;

import cn.edu.sdjzu.xg.eagle.entities.Teacher;
import cn.edu.sdjzu.xg.eagle.service.inface.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;
import java.util.List;

@RestController
@RequestMapping("teachers")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @GetMapping("/{id}")
    public Teacher getTeacher(@PathVariable int id) throws SQLException {
        return teacherService.getTeacher(id);
    }

    @GetMapping
    public List<Teacher> getTeachers() throws SQLException {
        return teacherService.getTeachers();
    }

    @PostMapping
    public String addTeacher(@RequestBody Teacher teacher) throws SQLException {
        return teacherService.addTeacher(teacher);
    }

    @PutMapping
    public String updateTeacher(@RequestBody Teacher teacher) throws SQLException {
        return teacherService.updateTeacher(teacher);
    }

    @DeleteMapping("/{id}")
    public String deleteTeacher(@PathVariable int id) throws SQLException {
        return teacherService.deleteTeacher(id);
    }
}